package com.itheima.w_conf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Slf4j
@Configuration
@EnableSwagger2 // 貌似被弃用，可以替换为@EnableSwagger2
public class Knife4jConfiguration {
    @Autowired
    private void init(){
        log.info("Swagger2启动成功,原始访问可以在浏览器中查看文档了! http://localhost:8080/swagger-ui.html");
        log.info("Swagger2启动成功,最新访问可以在浏览器中查看文档了! http://localhost:8080/doc.html");
    }

	@Value("${swagger.enable}")
    private Boolean enable;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
        		.enable(enable)
                .apiInfo(
                	new ApiInfoBuilder()
					.title("swagger-bootstrap-ui-demo RESTful APIs")
	                .description("# swagger-bootstrap-ui-demo RESTful APIs")
	                .termsOfServiceUrl("http://loclhost:8080")
	                .version("1.0")
	                .build()
                )
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定你自己的Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.itheima"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
